package com.qxzn.app.personalcenter.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxzn.app.bean.BindRobotUserBean;
import com.qxzn.app.personalcenter.R;
import com.qxzn.app.personalcenter.R2;
import com.qxzn.app.util.DateUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BindRobotUserAdapter extends RecyclerView.Adapter<BindRobotUserAdapter.ViewHolder> {

    private Activity activity;
    private List<BindRobotUserBean.DataBean> dataList;
    private BindRobotUserBean.DataBean item;

    public BindRobotUserAdapter(Activity activity, List dataList) {
        this.activity = activity;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_contacts, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        item = dataList.get(position);
        holder.name.setText(item.getUsername());
        holder.phone.setText(DateUtil.formMillisToStr(item.getRecord_time()));
        holder.tvStatus.setVisibility(View.VISIBLE);
        if ("1".equals(dataList.get(position).getRoles())) {
            holder.tvStatus.setText("已绑定");
            holder.tvStatus.setTextColor(activity.getResources().getColor(R.color.green));
        } else {
            holder.tvStatus.setText("待授权");
            holder.tvStatus.setTextColor(activity.getResources().getColor(R.color.red_FF2A00));
        }
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.iv_head)
        ImageView ivHead;
        @BindView(R2.id.name)
        TextView name;
        @BindView(R2.id.phone)
        TextView phone;
        @BindView(R2.id.tv_status)
        TextView tvStatus;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
